{extend name="main" /}

{block name="body"}
{include file="breadcrumb" /}
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <form action="{:request()->url()}" method="post" class="xn_ajax">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" class="layui-input" value="{$data.title}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-block">
                <input type="text" name="keywords" id="keywords" class="layui-input" value="{$data.keywords}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">行业类型</label>
            <div class="layui-input-inline">
                <select name="parent_typeid" lay-filter="parent_typeid" id="parent_typeid">
                    <option value="0">选择类型</option>
                    {foreach name="parent_typelist" item="vo"}
                    <option value="{$vo.id}" {if condition="$data.parent_typeid eq $vo.id"}selected{/if} >{$vo.title}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="typeid" id="typeid">
                    <option value="0">选择类型</option>
                    {foreach name="typelist" item="vo"}
                    <option value="{$vo.id}" {if condition="$data.typeid eq $vo.id"}selected{/if} >{$vo.title}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属项目</label>
            <div class="layui-input-block layui-form-select">
                <input type="text" name="project" id="project" class="layui-input" value="{$data.project}">
                <dl class="layui-anim layui-anim-upbit" id="projectList">
                </dl>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">简介</label>
            <div class="layui-input-block">
                <textarea name="description" class="layui-textarea">{$data.description}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">属性</label>
            <div class="layui-input-block">
                <input type="text" name="attr" placeholder="" autocomplete="off" class="layui-input" value="{$data.attr}">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block" id="tags">
                <blockquote class="layui-elem-quote layui-quote-nm">
                列表：
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">列表.条件</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">列表.优势</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">列表.流程</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">列表.支持</button>
                </div>
                <br/>
                表格：
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">表格.费用</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">表格.利润</button>
                </div>
                <br/>
                文本：
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文本.过渡.费用</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文本.过渡.利润</button>
                </div>
                <br/>
                图片：
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">图片.大类</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">图片.小类</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">图片.项目</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">图片合成.大类</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">图片合成.小类</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">图片合成.项目</button>
                </div>
                <br/>
                文章段落：
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.首段</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.尾段</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.靠谱</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.真假</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.骗局</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.前景</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.生意</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.赔亏</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.怎么样</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.好不好</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.值吗</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.赚钱</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.怎么加盟</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">文章段落.口碑</button>
                </div>
                <br/>
                公司：
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">公司.名称</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">公司.成立时间</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">公司.注册资本</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">公司.地址</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">公司.省份</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">公司.城市</button>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">公司.法人</button>
                </div>
                </blockquote>
            </div>
            <div class="layui-input-block">
                <div class="layui-input-inline" style="width: 48%;">
                    <blockquote class="layui-elem-quote layui-quote-nm">
                        模板：
                        <div class="layui-inline">
                            <button id="makeContent" type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">生成</button>
                        </div>
                    </blockquote>
                    <textarea name="template" id="template">{$data.template}</textarea>
                </div>
                <div class="layui-input-inline" style="width: 48%;">
                    <blockquote class="layui-elem-quote layui-quote-nm">
                        内容：
                        <div class="layui-inline">
                            <button id="clearTag" type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">清除空标签</button>
                        </div>
                        <div class="layui-inline">
                            <button id="markViolation" type="button" class="layui-btn layui-btn-normal" style="background-color: #{:randColor()};">标红违禁词</button>
                        </div>
                    </blockquote>
                    <textarea name="content" id="content">{$data.content}</textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" lay-submit class="layui-btn">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="js"}
<!--编辑器-->
<script src="/static/admin/ueditor/ueditor.config.js"></script>
<script src="/static/admin/ueditor/ueditor.all.min.js"></script>
<script src="/static/admin/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    var ue = UE.getEditor('template',{
        initialFrameWidth : '100%',// 设置编辑器宽度
        initialFrameHeight:400,// 设置编辑器高度
        autoHeightEnabled: false
    });
    var ue_view = UE.getEditor('content',{
        initialFrameWidth : '100%',// 设置编辑器宽度
        initialFrameHeight:400,// 设置编辑器高度
        autoHeightEnabled: false
    });

    var tags = $('#tags').find('button');
    $.each(tags,function(index,item){
        $(item).click(function(){
            var str = '<p>[TAG:'+$(this).text()+']</p>';
            ue.focus();
            ue.execCommand('inserthtml', str);
        });
    });
    $(function(){
        $('#makeContent').click(function(){
            var dalei = $('#parent_typeid').find("option:selected").text();
            var xiaolei = $('#typeid').find("option:selected").text();
            var xiangmu = $('#project').val();

            var parent_typeid = $('#parent_typeid').find("option:selected").val();
            var typeid = $('#typeid').find("option:selected").val();

            var keywords = $('#keywords').val();
            var content = ue.getContent();
            $.post("{:url('ajaxMakePseudo')}",{dalei:dalei,xiaolei:xiaolei,xiangmu:xiangmu,content:content,parent_typeid:parent_typeid,typeid:typeid,keywords:keywords},function(res){
                if(res.status){
                    ue_view.ready(function() {
                        ue_view.setContent(res.data);
                    });
                }
                // layer.msg(res.msg,{time:1500});
            });
       });

       $('#clearTag').click(function(){
            var content = ue_view.getContent();
            content = content.replace(/<p>(\s|\&nbsp\;|<br\/>| |　|\xc2\xa0)*<\/p>/ig, "");
            ue_view.setContent(content);
       });

       $('#markViolation').click(function(){
            var content = ue_view.getContent();
            $.post("{:url('admin/ajax/ajaxMarkViolation')}",{content:content},function(result){
                if(result.status){
                    ue_view.setContent(result.data);
                }
            });
       });
    });

    var form = layui.form;
    form.on('select(parent_typeid)', function(res) { 
        $("#typeid").empty();
        if(res.value != 0){
            $.get("{:url('admin/DataType/getSonType')}?pid="+res.value,function(result){
                if(result.status){
                    $("#typeid").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        $("#typeid").append(new Option(item.title,item.id));
                    });
                    form.render("select");
                }
            });
        }else{
            $("#typeid").append(new Option('请选择',0));
            form.render("select");
        }
    })

    $(function(){
       $('#project').keyup(function(event){
            var word = $("#project").val().trim();
            if(word.length>0){
                $.get("{:url('admin/DataProject/getProjectByLike')}",{word:word},function(res){
                    if(res.status){
                        var html = '';
                        $.each(res.data,function(index,obj){
                            html += '<dd data-tid="'+obj.typeid+'" data-ptid="'+obj.parent_typeid+'">'+obj.title+'</dd>';
                        });
                        $('#projectList').html(html).css('display','block');
                    }else{
                        $('#projectList').html('').css('display','none');
                    }
                });
            }else{
                $('#projectList').html('').css('display','none');
            }
       });

       $('#projectList').on('click','dd',function(){
           var ptid = $(this).attr('data-ptid');
           var tid = $(this).attr('data-tid');

           $('#project').val($(this).text());
           $('#projectList').html('').css('display','none');
           
           var dd = $('#parent_typeid').next().find('dl dd[lay-value='+ptid+']');
           dd.click();

            $.get("{:url('admin/DataType/getSonType')}?pid="+ptid,function(result){
                if(result.status){
                    $("#typeid").empty();
                    $("#typeid").append(new Option('请选择',0));
                    $.each(result.data,function(index,item){
                        if(tid == item.id){
                            $("#typeid").append(new Option(item.title,item.id,false,true));
                        }else{
                            $("#typeid").append(new Option(item.title,item.id));
                        }
                    });
                    form.render("select");
                }
            });
           
       });
       $('#project').click(function(){
            if( $("#projectList").children().length ){
                $("#projectList").toggle();
            }
       });
   });
</script>
{/block}

